package com.biz.primus.ms.geo.dao.repository;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.ms.base.jpa.repository.CommonJpaRepository;
import com.biz.primus.ms.geo.dao.po.City;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author JKLiues
 * @date 2017/11/8
 */
@Repository
public interface CityRepository extends CommonJpaRepository<City, Integer>, CityDao {

    /**
     * 根据城市名称模糊查询
     *
     * @param name 城市名
     * @return 城市po集合
     */
    @Query("from City city where city.name like %?1%")
    List<City> findByNameOfLike(String name);

    /**
     * 根据省份id查询城市信息
     *
     * @param provinceId 省份id
     * @param pageable   分页
     * @return 城市po集合
     */
    @Query("from City city where city.provinceId = ?1 order by city.idx")
    Page<City> findCitiesByProvinceId(Integer provinceId, Pageable pageable);

    /**
     * 通过状态查市
     *
     * @param status 状态
     * @return List<City>
     */
    List<City> findByStatus(CommonStatus status);
}
